//一级路由
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
//二级路由
import GroupOrder from '@/pages/Center/GroupOrder'
import MyOrder from '@/pages/Center/MyOrder'

//路由配置信息
export default[
        //重定向，在项目跑起来的时候，访问直接就是首页
        // {
        //     path:"*",
        //     redirect:"/hemo"
        // },
        {
            path: '/center',
            component: Center,
            meta: { show: true },
            //二级路由组件
            children:[
                {
                    path: 'grouporder',
                    component: GroupOrder,
                    // meta: { show: true },
                },
                {
                    path: 'myorder',
                    component: MyOrder,
                    // meta: { show: true },
                },
            ]
        },
        {
            path: '/paysuccess',
            component: PaySuccess,
            meta: { show: true },
        },
        {
            path: '/pay',
            component: Pay,
            meta: { show: true },
            beforeEnter: (to, from, next) => {
                //提交订单页面，必须是购物车页跳转才放行
                if(from.path == "/trade"){
                    next()
                }else{
                    next(false)
                }
            }
        },
        {
            path: '/trade',
            component: Trade,
            meta: { show: true },
            beforeEnter: (to, from, next) => {
                //提交订单页面，必须是购物车页跳转才放行
                if(from.path == "/shopcart"){
                    next()
                }else{
                    next(false)
                }
            }
        },
        {
            path: '/shopcart',
            component: ShopCart,
            meta: { show: true },
        },
        {
            path: '/addcartsuccess',
            component: AddCartSuccess,
            meta: { show: true },
            name:'addcartsuccess',
        },
        {
            path: '/detail/:skuId',
            component: Detail,
            meta: { show: true }
        },
        {
            path: '/home',
            //路由懒加载
            component:()=>import('@/pages/Home'),
            meta: { show: true }
        },
        {
            path: '/login',
            component:()=>import('@/pages/Login'),
            meta: { show: false }
        },
        {
            path: '/register',
            component: Register,
            meta: { show: false }
        },
        {
            path: '/search/:keyword?',
            component: Search,
            meta: { show: true },
            name: 'search'
        },
    ]